package com.hibase.core.log.controller;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.log.entity.MdsOperationLog;
import com.hibase.core.log.entity.vo.*;
import com.hibase.core.log.service.MdsOperationLogService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author chenfeng
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/mds-operation-log")
@Api(tags = "操作日志")
public class MdsOperationLogController {

    @Autowired
    private MdsOperationLogService mdsOperationLogService;

    @ApiOperation(value = "查询操作日志列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectMdsOperationLogList")
    public ResponseModel<MdsOperationLogListVO> selectMdsOperationLogList(@RequestBody MdsOperationLogSearchVO searchVO) {

        PageInfo result = mdsOperationLogService.selectMdsOperationLogList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsOperationLogListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增操作日志记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertMdsOperationLog")
    public ResponseModel<String> insertMdsOperationLog(@RequestBody MdsOperationLogInsertVO insertVO) {

        MdsOperationLog entity = EntityUtil.transform(insertVO, MdsOperationLog.class);

        mdsOperationLogService.saveMdsOperationLog(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改操作日志记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateMdsOperationLog")
    public ResponseModel<String> updateMdsOperationLog(@RequestBody MdsOperationLogUpdateVO updateVO) {

        MdsOperationLog entity = EntityUtil.transform(updateVO, MdsOperationLog.class);

        mdsOperationLogService.saveMdsOperationLog(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询操作日志详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewMdsOperationLogDetails")
    public ResponseModel<MdsOperationLogViewVO> viewMdsOperationLogDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsOperationLogService.viewMdsOperationLog(operationidEntity.getId()), MdsOperationLogViewVO.class));
    }

    @ApiOperation(value = "删除操作日志记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteMdsOperationLog")
    public ResponseModel<String> deleteMdsOperationLog(@RequestBody OperationIdEntity delete) {

        mdsOperationLogService.deleteMdsOperationLog(delete.getId());

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "查询日志列表top", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectList")
    public ResponseModel<MdsOperationLogListVO> selectList(@RequestBody MdsOperationLogSearchVO searchVO) {

        PageInfo result = mdsOperationLogService.selectMdsOperationLogList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsOperationLogListVO.class));

        return ResponseModel.successMsg(result);
    }
}
